#ifndef _CONFIGURE_H_
#define _CONFIGURE_H_

#include "esp_gatts_api.h"
#include "gatts.h"

/**
 * @brief 包含封装和底层数据类型，用作接口/数据转换的类型
 */
struct configure {
	// esp_gatts_cb_t gatts_cb;
	uint16_t gatts_if;
	uint16_t conn_id;
	const char *device_name;
	struct gatts_profile *profile;
	esp_gatts_attr_db_t *attr_db;
	uint8_t attr_num;
	uint8_t service_num;
	uint8_t char_num;
	uint8_t cccd_num;
	uint16_t *handle_list;
	uint8_t *service_idx;
	uint8_t *char_val_idx;
	uint8_t *cccd_idx;
	struct gatts_uuid **char_cccd_uuid;
	struct gatts_uuid **char_uuid;
};

/**
 * @brief 根据profile配置configure
 * @param profile
 * @return void
 */
void gatts_configure(struct gatts_profile *profile);

/**
 * @brief 取消配置，释放configure相关内存
 * @param profile
 * @return void
 */
void gatts_unconfigure();

/**
 * @brief 根据handle值获取其在列表中的索引
 * @param handle handle值
 * @param handle_list handle列表
 * @param handle_num handle列表元素个数
 * @return 返回索引
 */
int get_idx_by_handle(uint16_t handle);

bool handle_is_cccd(uint16_t handle);

/**
 * @brief 根据char handle值获取char_uuid
 * @param handle handle值
 * @return 成功返回uuid指针，失败返回NULL
 */
struct gatts_uuid *get_char_uuid_by_char_handle(uint16_t handle);

/**
 * @brief 根据cccd handle值获取char_uuid
 * @param handle handle值
 * @return 成功返回uuid指针，失败返回NULL
 */
struct gatts_uuid *get_char_uuid_by_cccd_handle(uint16_t handle);

/**
 * @brief 根据handle值获取char_uuid
 * @param handle handle值
 * @return 成功返回uuid指针，失败返回NULL
 */
struct gatts_uuid *get_char_uuid_by_handle(uint16_t handle);

/**
 * @brief 根据uuid值获取cccd_handle
 * @param uuid uuid
 * @param handle 被修改的handle
 * @return 成功返回true，失败返回false
 */
bool get_cccd_handle_by_uuid(const struct gatts_uuid *uuid, uint16_t *handle);

/**
 * @brief 根据cccd_handle值获取uuid
 * @param uuid uuid
 * @param handle 被修改的handle
 * @return 成功返回true，失败返回false
 */
bool get_char_handle_by_uuid(const struct gatts_uuid *uuid, uint16_t *handle);

// int get_cccd_idx_by_uuid(const struct gatts_uuid *uuid);

void print_configure();
#endif